<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%> 
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="<%=basePath %>css/pagination.css">
        <link rel="stylesheet" href="<%=basePath %>css/cssreset.css">
        <link rel="stylesheet" href="<%=basePath %>css/style2.css">
		<script src="<%=basePath %>js/jquery-1.11.1.min.js"></script>
		 <script>
		       $(function(){
		       	$(".newht").click(function(e){
			        e.preventDefault();
			        $('body').css("overflow","hidden");
			        $("#cover4").css("display","block");
			        $("#cover4").animate({
			            width: "100%",
			            height: "1800px",
			            top: "0",
			            left: "0"
			        },10);
			        
			    });
			    $(".close").click(function(){
			    	$('body').css("overflow","scroll");
			        $("#cover4").removeAttr("style");
			        $("#cover-content3").removeAttr("style");
			    });
		       })
		  </script> 
        
    </head>
    <body>
    	<div class="bigbox2">
    		<nav class="nav2">
    			<span class="scolor"></span>
    			<ul>
    				<li><a href="<%=basePath %>page/originalIndex.jsp"><p class="mline"><span class="smallicon"></span><span class="navtxt">首 页</span></p></a></li>
    				<li><a href="<%=basePath %>client/findByIndex.action"><p class="mline"><span class="smallicon one1" ></span><span class="navtxt" >客 户</span></p></a></li>
    				<li><a href="<%=basePath %>sale/findSale.action"><p class="mline"><span class="smallicon one2"></span><span class="navtxt">销 售 机 会</span></p></a></li>
    				<li><a href="<%=basePath %>contact/page.action"><p class="mline"><span class="smallicon one3"></span><span class="navtxt">联 系 人</span></p></a></li>
    				<li><a href="<%=basePath %>contract/findByAlls.action"  id="sline"><p class="mline"><span class="smallicon one4" id="current21"></span><span class="navtxt" id="current2">合 同</span></p></a></li>
    				<li class="shenpi"><a href="<%=basePath %>page/pacts.jsp"><p class="mline"><span class="smallicon one8"></span><span class="navtxt">合 同 审 批</span></p></a></li>
    				<c:if test="${sessionScope.backstage == 1}">
   						<li><a href="<%=basePath %>staff/selectTree.action"><p class="mline"><span class="smallicon one5"></span><span class="navtxt">后 台 管 理</span></p></a></li>
    				</c:if>
    			</ul>
    		</nav>
    		<div class="showbox3">
	    		<p class="xtitle">合 同 详 情</p>
	    		<span class="boxone">
	    		<div class="above">
	    			<img src="<%=basePath %>images/ht22.png" alt="" class="po"> 
		    		<span class="salename">
		    		&nbsp;${contract.contractTitle}

		    		</span>
		    		<span class="open">
		    			<span class="opennew newht" style="margin-left:90%;">编 辑</span>
		    			
		    		</span>
	    		</div>
		    	<ul class="sun sun2">
		    		<li>
		    			<span class="sone">客户</span><br>
		    			<span class="stwo" id="kehuname">${contract.clientName}</span>
		    		</li>
		    		<li>
		    			<span class="sone">合同状态</span><br>
		    			<span class="stwo">${contract.contracttype}</span>
		    		</li>
		    		<li>
		    			<span class="sone">开始日期</span><br>
		    			<span class="stwo" id="startDate"><fmt:formatDate value="${contract.contractStartDate}" type="date"/></span>
		    			
		    		</li>
		    		<li>
		    			<span class="sone">结束日期</span><br>
		    			<span class="stwo">
		    				<fmt:formatDate value="${contract.contractCloseDate}" type="date"/>
		    			</span>
		    		</li>
		    		<li>
		    			<span class="sone">合同所有人</span><br>
		    			<span class="stwo">${contract.staffName}</span>
		    		</li>
		    		

		    	</ul>		
	    		</span> 
	    		<div class="b-box"></div>	   		
    		</div>
    		<div class="showbox3 showbox4">
	    		  <div class="boxtwo">
	    		  
	    		  	
	    		  	<div class="boxthree">
	    		  		<span class="threenav threenav2">
	    		  			
	    		  			<a href="<%=basePath %>html/sale2.html">资料</a>
	    		  		</span>
	    		  		<div class="formdan">
	    		  			<p>基本信息</p>
	    		  			<ul class="basictxt">
	    		  				<li>
	    		  					<span class="crazy">业务类型</span>
	    		  					<span class="crazy2">${contract.contractBusinesstype}</span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">主题</span>
	    		  					<span class="crazy2">${contract.contractTitle}</span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">客户</span>
	    		  					<span class="crazy2">${contract.clientName}</span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">销售机会</span>
	    		  					<span class="crazy2" id="sale_saleOpportunityName">${sale.saleOpportunityName}</span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">合同类型</span>
	    		  					<span class="crazy2" id="contract_contracttype">${contract.contracttype}</span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">总金额</span>
	    		  					<span class="crazy2">${contract.contractAmount}</span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">合同状态</span>
	    		  					<span class="crazy2" id="contract_contractStatus">${contract.contractStatus}</span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">付款方式</span>
	    		  					<span class="crazy2" id="contract_contractPaymode">${contract.contractPaymode}</span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">开始日期</span>
	    		  					<span class="crazy2"><fmt:formatDate value="${contract.contractStartDate}" type="date"/> </span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">结束日期</span>
	    		  					<span class="crazy2" id="contractProductss"><fmt:formatDate value="${contract.contractCloseDate}" type="date"/></span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">产品</span>
	    		  					<span class="crazy2">${contract.contractProduct}</span>
	    		  				</li>
	    		  			</ul>
	    		  			<p>其他信息</p>
	    		  			<ul class="basictxt">
	    		  				<li>
	    		  					<span class="crazy">合同正文</span>
	    		  					<span class="crazy2">${contract.contractContent}</span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">合同编号</span>
	    		  					<span class="crazy2">${contract.contractCode}</span>
	    		  				</li>
	    		  				
	    		  				<li>
	    		  					<span class="crazy">合同所有人</span>
	    		  					<span class="crazy2">${contract.staffName}</span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">客户方签约人</span>
	    		  					<span class="crazy2">${contract.contractCustomerSigner}</span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">我方签约人</span>
	    		  					<span class="crazy2">${contract.contractSigner}</span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">签约日期</span>
	    		  					<span class="crazy2" id="contract_contractSigndate"><fmt:formatDate value="${contract.contractSigndate}" type="date"/></span>
	    		  					
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">所属部门</span>
	    		  					<span class="crazy2" id="contract_departmentName">${contract.departmentName}</span>
	    		  				</li>
	    		  				<li>
	    		  					<span class="crazy">备注</span>
	    		  					<span class="crazy2">${contract.contractSignremark}</span>
	    		  				</li>
	    		  				
	    		  			</ul>
	    		  		</div>
	    		  		
	    		  		

	    		  	</div>
	    		  </div>		
    		</div>
    		<div id="cover4">
						<div id="cover-bg3"></div>
						<div id="cover-content3">
							<h4>修 改 合 同<span class="close"></span></h4>
							<p class="main">
								<span class="leftmain">业务类型</span>
								<span class="name" id="contractBusinesstype">默认业务类型</span>
							</p>
							<p class="main">
								<span class="leftmain">主 题&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
								<input type="text" id="contractTitle" placeholder="&nbsp;&nbsp;请输入主题 " value="${contract.contractTitle}" class="shurukuang">
							</p>
							
							<p class="main">
								<span class="leftmain">客 户&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
								<select id="onecli" class="shenfenselect shenfenselect3" onchange="selectSale()">
						            <c:forEach items="${clients}" var="client">
						            	<option value="${client.client_id}">${client.client_name}</option>
						            </c:forEach>
						        </select>
							</p>
							<p class="main">
								<span class="leftmain">销 售 机 会</span>
								<select id="saleId" class="shenfenselect shenfenselect3">
						            <c:forEach items="${slaes}" var="slaes">
						            	<option value="${slaes.slaesId}">${slaes.saleOpportunityName}</option>
						            </c:forEach>
						           
						        </select>
							</p>
							<p class="main">
								<span class="leftmain">总 金 额&nbsp;&nbsp;&nbsp;&nbsp;</span>
								<input type="text" value="${contract.contractAmount}" id="contractAmount" placeholder="&nbsp;&nbsp;请输入总金额 " class="shurukuang">
							</p>
							<p class="main">
								<span class="leftmain">付 款 方 式</span>
								<select id="onecl" class="shenfenselect shenfenselect3">
						            <option value="支票">&nbsp;支票</option>
						            <option value="现金">&nbsp;现金</option>
						            <option value="银行转账">&nbsp;银行转账</option>
						            <option value="其他">&nbsp;其他</option>
						           
						        </select>
							</p>
							<p class="main">
								<span class="leftmain">开 始 日 期</span>
								<input type="text" id="contractStartDate" value="${contract.contractStartDate}" class="shurukuang Wdate" style="height: 30px;1px solid #bfbfbf;" placeholder="&nbsp;&nbsp;请输入开始日期 "  onfocus="WdatePicker({skin:'whyGreen',dateFmt: 'yyyy-MM-dd', readOnly:true})">
							</p>
							<p class="main">
								<span class="leftmain">结 束 日 期</span>
								<input type="text" id="contractCloseDate" value="${contract.contractCloseDate}" class="shurukuang Wdate" style="height: 30px;1px solid #bfbfbf;" placeholder="&nbsp;&nbsp;请输入结束日期 "  onfocus="WdatePicker({skin:'whyGreen',dateFmt: 'yyyy-MM-dd', readOnly:true})">
								
							</p>
							
							<p class="main">
								<span class="leftmain">签 约  日 期</span>
								<input type="text" id="contractSigndate" value="${contract.contractSigndate}" class="shurukuang Wdate" style="height: 30px;1px solid #bfbfbf;" placeholder="&nbsp;&nbsp;请输入签约日期 "  onfocus="WdatePicker({skin:'whyGreen',dateFmt: 'yyyy-MM-dd', readOnly:true})">
							</p>
							<p class="main">
								<span class="leftmain">合 同 所 有 人</span>
								<span class="none" id="staff_name">${contract.staffName}</span>
							</p>
							
							<p class="main">
								<span class="leftmain">合 同 编 号</span>
								<input type="text" value="${contract.contractCode}" id="contractCode" placeholder="&nbsp;&nbsp; " class="shurukuang">
							</p>
							
							<p class="main">
								<span class="leftmain">合 同 正 文</span>
								<textarea style="border:1px solid #bfbfbf;border-radius:5px;color:#bfbfbf;" rows="" cols="" id="contractContent" cols="30" rows="10">${contract.contractContent}</textarea>
							</p>
							
							<p class="main">
								<span class="leftmain">产 品&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
								<input type="text" value="${contract.contractProduct}" id="contractProduct" placeholder="&nbsp;&nbsp; " class="shurukuang">
							</p>
							
							<p class="main">
								<span class="leftmain">我 方 签 约 人&nbsp;&nbsp;&nbsp;&nbsp;</span>
								<input type="text" id="contractSigner" placeholder="&nbsp;&nbsp; " style="margin-left:-7px;" class="shurukuang" value="${contract.contractSigner}">
							</p>
							
							<p class="main">
								<span class="leftmain">客户方签约人&nbsp;&nbsp;&nbsp;&nbsp;</span>
								<input type="text" id="contractCustomerSigner" placeholder="&nbsp;&nbsp; " class="shurukuang" value="${contract.contractCustomerSigner}">
							</p>
							
							<p class="main">
								<span class="leftmain">所 属 部 门</span>
								<select id="onedeps" class="shenfenselect shenfenselect3">
						            <option value="">请选择</option>
						            <c:forEach items="${departments}" var="department">
						            	<option value="${department.department_name}">${department.department_name}</option>
						            </c:forEach>
						        </select>
							</p>
							
							<p class="main">
								<span class="leftmain">合 同 类 型</span>
								<select id="onecees" class="shenfenselect shenfenselect3">
						            <option value="">请选择合同类型</option>
						             <c:forEach items="${compactGenres}" var="compactGenre">
						            	<option value="${compactGenre.compactName}">${compactGenre.compactName}</option>
						            </c:forEach>
						        </select>
							</p>
							
							<p class="main">
								<span class="leftmain">合 同 状 态</span>
								<select id="contractStatus" class="shenfenselect shenfenselect3">
						            <option value="执行中">执行中</option>
						            <option value="结束">结束</option>
						            <option value="意外终止">意外终止</option>
						            
						        </select>
							</p>
							<p class="main">
								<span class="leftmain">签 约 备 注</span>
								<input type="text" value="${contract.contractSignremark}" id="contractSignremarks" class="shurukuang">
							</p>
							
							<p class="main" style="padding-bottom:30px;">
								<button class="btn1 btn2" onclick="saveContract()">保存</button>
								<button class="btn1 btn3 btn555">取消</button>
							</p>
						</div>
					</div>
    	</div>
    	<p id="contractId" style="display:none">${contract.contractId}</p>
    	<script src="${pageContext.request.contextPath}/salejihui/My97DatePicker/WdatePicker.js"></script>
    	
    </body>
    <script type="text/javascript">
    
	    function selectSale(){
	    	var id = $("#onecli").val();
	    	$.ajax({
				type:"post",
				url:"<%=basePath %>contract/findxiaoshoujihui.action",
				data:"id="+id,
				success:function(data){
					$("#saleId").html("");
		    	    var baa = "<option value=''>请选择</option>";
		    	    $("#saleId").append(baa);
					var dep = eval("("+data+")");
					for(var i=0;i<dep.length;i++){
						var depar = dep[i];
						var depass = "<option value='"+depar.saleId+"'> "+ depar.saleOpportunityName+"</option>";
						$("#saleId").append(depass);
					}
				},
				error:function(e){
					alert("发生未知错误请刷新页面");
				}
	
	   		 });
	    }
	    
	    function saveContract(){
	    	var onecli = $("#onecli").val();
	    	if(onecli == 0){
	    		alert("客户不能为空");
	    		return;
	    	}
	    	onecli = $("#onecli").find("option:selected").text();
	    	var contractId = $("#contractId").html();
	    	var contractBusinesstype = "默认业务类型";
	    	var saleI = $("#saleId").val();
	    	var contractTitle = $("#contractTitle").val();
	    	var contractAmoun = $("#contractAmount").val();
	    	var onecl = $("#onecl").val();
	    	var contractStartDat = $("#contractStartDate").val();
	    	var contractCloseDat = $("#contractCloseDate").val();
	    	var contractSigndate = $("#contractSigndate").val();
	    	var contractContent = $("#contractContent").val();
	    	var staff_name= $("#staff_name").html();
	    	var contractCod = $("#contractCode").val();
	    	var contractProduc = $("#contractProduct").val();
	    	var contractSigne = $("#contractSigner").val();
	    	var contractCustomerSigne = $("#contractCustomerSigner").val();
	    	var onedep = $("#onedeps").find("option:selected").text();
	    	var onecee = $("#onecees").find("option:selected").text();
	    	var contractStatu = $("#contractStatus").val();
	    	var remark = $("#contractSignremarks").val();
	    	var usdata = {contractBusinesstype:contractBusinesstype,clientName:onecli,saleId:saleI,contractId:contractId,
	    				  contractTitle:contractTitle,contractAmount:contractAmoun,contractPaymode:onecl,
	    				  contractStartDate:contractStartDat,contractCloseDate:contractCloseDat,staffName:staff_name,
	    				  contractCode:contractCod,contractProduct:contractProduc,contractSigner:contractSigne,contractCustomerSigner:contractCustomerSigne,
	    				  departmentName:onedep,contracttype:onecee,contractStatus:contractStatu,contractSigndate:contractSigndate,
	    				  contractContent:contractContent,contractSignremark:remark};
	    	$.ajax({
				type:"post",
				url:"<%=basePath %>contract/updateContract.action",
				data:usdata,
				success:function(data){
					alert(data);
					if(data == "修改成功"){
						location.href="<%=basePath %>contract/selectById.action?id="+contractId;
					}
				},
				error:function(e){
					alert("发生未知错误请刷新页面");
				}

	   		 });
	    }
	    var namessa = $("#kehuname").html();
	    $("#onecli").find("option[text='"+namessa+"']").attr("selected",true);  
	    
	    var sale_saleOpportunityName = $("#sale_saleOpportunityName").html();
	    $("#saleOpportunityName").find("option[text='"+sale_saleOpportunityName+"']").attr("selected",true); 
	    
	    var contract_contractPaymode = $("#contract_contractPaymode").html();
	    $("#onecliaa").find("option[value='"+contract_contractPaymode+"']").attr("selected",true);
	    
	    var contract_contracttype = $("#contract_contracttype").html();
	    $("#contracttype").find("option[value='"+contract_contracttype+"']").attr("selected",true);
	    
	    var contract_contracttype = $("#contract_contracttype").html();
	    $("#contracttype").find("option[value='"+contract_contracttype+"']").attr("selected",true);
	    
	    var contract_departmentName = $("#contract_departmentName").html();
	    $("#onedeps").find("option[value='"+contract_departmentName+"']").attr("selected",true);
	    
	    
	    var contract_contracttype = $("#contract_contracttype").html();
	    $("#onecees").find("option[value='"+contract_contracttype+"']").attr("selected",true);
	    
	    
	    var contract_contractStatus = $("#contract_contractStatus").html();
	    $("#contractStatus").find("option[value='"+contract_contractStatus+"']").attr("selected",true);
	    
	    var datess = $("#contract_contractSigndate").html();
	    $("#contractSigndate").val(datess);
	    
	    var contractProductss = $("#contractProductss").html();
	    $("#contractCloseDate").val(contractProductss);
	    
	    var startDate = $("#startDate").html();
	    $("#contractStartDate").val(startDate);
	    
	    $(".btn555").click(function(){
	        $("#cover4").removeAttr("style");
	        $("#cover-content3").removeAttr("style");
	    });
	    
    </script>
</html>
